package com.pagoda.nerp.web.repositories;

import com.pagoda.nerp.web.entities.HRZGZD;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Set;

@Transactional
public interface HRZGZDDao extends PagingAndSortingRepository<HRZGZD,String>,JpaSpecificationExecutor<HRZGZD> {
    @Query(value = "select * from hrzgzd hr where  hr.dept in :depts and hr.postcode in :postcodes and hr.name like %:mname% and hr.code like :code% and hr.mobile like :mobile% order by ?#{#pageable}",
            countQuery = "select count(*) from hrzgzd hr where  hr.dept in :depts and hr.postcode in :postcodes and hr.name like %:mname% and hr.code like :code% and hr.mobile like :mobile% order by ?#{#pageable}",
            nativeQuery = true)
    public Page<HRZGZD> getHRZGZDList(
                                      @Param("depts") Set<String> depts,
                                      @Param("postcodes") Set<String> codes,
                                      @Param("mname") String mname,
                                      @Param("code")String code,
                                      @Param("mobile")String mobile,
                                      Pageable pageable
                                     );
    public HRZGZD findByCode(String code);

}
